class pack:
    def __init__(self,cluCenter:int,posi):
        global packNum
        self.no=packNum
        packNum+=1
        self.allPos=[]
        self.allPos.append(posi)
        self.cluCenter=cluCenter
        if cluCenter==0:
            self.dist = q3.dist(posi[0], posi[1], q3.estimator.cluster_centers_[0, 0],
                                q3.estimator.cluster_centers_[0, 1])
        elif cluCenter==1:
            self.dist = q3.dist(posi[0], posi[1], q3.estimator.cluster_centers_[1, 0],
                                q3.estimator.cluster_centers_[1, 1])
        else:
            self.dist = q3.dist(posi[0], posi[1], q3.estimator.cluster_centers_[2, 0],
                                q3.estimator.cluster_centers_[2, 1])
        self.price = model.predict(self.dist)
        allPack.append(self)

    def add(self,pos,dist:float):
        newdist=self.dist+dist
        if newdist>=distThreshold:
            return False
        elif self.cluCenter==0 and len(self.allPos)>=C1mean:
            return False
        elif self.cluCenter==1 and len(self.allPos)>=C2mean:
            return False
        elif self.cluCenter==2 and len(self.allPos)>=C3mean:
            return False
        else:
            self.allPos.append(pos)
            self.dist+=dist
            self.price = model.predict(self.dist)
            return True

def doPack(code,jingwei):
    packing = None
    for posi in jingwei:
        if posi is None:
            continue
        while True:
            posj = min(jingwei, key=lambda x: getDist(posi, x))
            d = getDist(posi, posj)

            if packing is None:
                packing = pack(code, posi)
                findSetNone(posi, jingwei)  # 添加成功立刻置None

            r = packing.add(posj, d)

            if not r:  # 添加失败（j没添加进去）
                packing = None
                break
            else:
                findSetNone(posj, jingwei)  # 添加成功立刻置None
                posi = posj  # j添加进去了，查找链路的下个节点

doPack(0,C1JingWei)
doPack(1,C2JingWei)
doPack(2,C3JingWei)